package com.mayikt;

/**
 * @Author: maplefire
 * @Description: 用户线程与守护线程
 * @Date: 2022/06/16 18:12
 */

public class ThreadDemo04 {
    public static void main(String[] args) {
        Thread t1 = new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 30; i++) {
                    try {
                        Thread.sleep(300);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println("子线程,i:" + i);
                }
            }
        });
        // 将t1线程设置为守护线程，主线程停止守护线程停止
        t1.setDaemon(true);
        t1.start();
        for (int i = 0; i < 5; i++) {
            try {
                Thread.sleep(300);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("主线程,i:" + i);
        }
        System.out.println("主线程执行完毕");
    }
}
